const router = require("koa-router")()
const { login, register, logout, forgetPassword, updateInfo, profileAvatar } = require('../services/admin')
const { classifyAdd, classifyDelete, classifyEdit, classifyList } = require('../services/classify')
const { libraryList, libraryAdd, libraryDelete, libraryEdit } = require('../services/library')
const { noticeList, noticeAdd, noticeDelete, noticeEdit } = require('../services/notice')

const token = require('../utils/token')
/**
* @swagger
* tags:
*   name: 后台管理
*   description: admin management
*/
/**
* @swagger
* tags:
*   name: 后台管理-产品分类
*   description: 产品分类
*/
/**
* @swagger
* tags:
*   name: 后台管理-产品库
*   description: 产品库
*/
router.prefix("/apis-admin")
/**
 * @swagger
 * definitions:
 *  loginParam:
 *    properties:
 *      userName:
 *        type: "string"
 *        default: "jwzs"
 *        description: 用户名
 *      password:
 *        type: "string"
 *        default: "123456"
 *        description: 密码
 */

/**
 * @swagger
 * definitions:
 *  addClassifyBody:
 *    properties:
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 标题
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      status:
 *        type: "string"
 *        default: "0"
 *        description: 状态 0=正常，1=停用
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 */

/**
 * @swagger
 * definitions:
 *  editClassifyBody:
 *    properties:
 *      classifyId:
 *        type: "string"
 *        default: ""
 *        description: 产品分类ID
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 标题
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      status:
 *        type: "string"
 *        default: "0"
 *        description: 状态 0=正常，1=停用
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 */

/**
 * @swagger
 * definitions:
 *  addLibraryBody:
 *    properties:
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 用户名
 *      productDescribe:
 *        type: "string"
 *        default: ""
 *        description: 产品描述
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      brand:
 *        type: "string"
 *        default: ""
 *        description: 产品品牌商
 *      price:
 *        type: "string"
 *        default: ""
 *        description: 产品价格
 *      discounted_price:
 *        type: "string"
 *        default: ""
 *        description: 产品折扣价格
 *      model:
 *        type: "string"
 *        default: ""
 *        description: 产品型号
 *      material_quality:
 *        type: "string"
 *        default: ""
 *        description: 产品材质
 *      specifications:
 *        type: "string"
 *        default: ""
 *        description: 产品规格
 *      features:
 *        type: "string"
 *        default: ""
 *        description: 产品特性
 *      showImg:
 *        type: "string"
 *        default: ""
 *        description: 产品详细图片展示,图片地址以逗号分隔的形式上传
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 *      classifyId:
 *        type: "string"
 *        default: "101"
 *        description: 产品分类
 */

/**
 * @swagger
 * definitions:
 *  editLibraryBody:
 *    properties:
 *      libraryId:
 *        type: "string"
 *        default: ""
 *        description: 产品ID
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 标题
 *      productDescribe:
 *        type: "string"
 *        default: ""
 *        description: 产品描述
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      brand:
 *        type: "string"
 *        default: ""
 *        description: 产品品牌商
 *      price:
 *        type: "string"
 *        default: ""
 *        description: 产品价格
 *      discounted_price:
 *        type: "string"
 *        default: ""
 *        description: 产品折扣价格
 *      model:
 *        type: "string"
 *        default: ""
 *        description: 产品型号
 *      material_quality:
 *        type: "string"
 *        default: ""
 *        description: 产品材质
 *      specifications:
 *        type: "string"
 *        default: ""
 *        description: 产品规格
 *      features:
 *        type: "string"
 *        default: ""
 *        description: 产品特性
 *      status:
 *        type: "string"
 *        default: "0"
 *        description: 状态 0=正常，1=停用
 *      showImg:
 *        type: "string"
 *        default: ""
 *        description: 产品详细图片展示,图片地址以逗号分隔的形式上传
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 *      classifyId:
 *        type: "string"
 *        default: "101"
 *        description: 产品分类
 */

/**
 * @swagger
 * definitions:
 *  addNoticeBody:
 *    properties:
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 用户名
 *      productDescribe:
 *        type: "string"
 *        default: ""
 *        description: 产品描述
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      brand:
 *        type: "string"
 *        default: ""
 *        description: 产品品牌商
 *      price:
 *        type: "string"
 *        default: ""
 *        description: 产品价格
 *      discounted_price:
 *        type: "string"
 *        default: ""
 *        description: 产品折扣价格
 *      model:
 *        type: "string"
 *        default: ""
 *        description: 产品型号
 *      material_quality:
 *        type: "string"
 *        default: ""
 *        description: 产品材质
 *      specifications:
 *        type: "string"
 *        default: ""
 *        description: 产品规格
 *      features:
 *        type: "string"
 *        default: ""
 *        description: 产品特性
 *      showImg:
 *        type: "string"
 *        default: ""
 *        description: 产品详细图片展示,图片地址以逗号分隔的形式上传
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 *      classifyId:
 *        type: "string"
 *        default: "101"
 *        description: 产品分类
 */

/**
 * @swagger
 * definitions:
 *  editNoticeBody:
 *    properties:
 *      noticeId:
 *        type: "string"
 *        default: ""
 *        description: 产品ID
 *      title:
 *        type: "string"
 *        default: ""
 *        description: 标题
 *      productDescribe:
 *        type: "string"
 *        default: ""
 *        description: 产品描述
 *      cover:
 *        type: "string"
 *        default: ""
 *        description: 产品封面
 *      brand:
 *        type: "string"
 *        default: ""
 *        description: 产品品牌商
 *      price:
 *        type: "string"
 *        default: ""
 *        description: 产品价格
 *      discounted_price:
 *        type: "string"
 *        default: ""
 *        description: 产品折扣价格
 *      model:
 *        type: "string"
 *        default: ""
 *        description: 产品型号
 *      material_quality:
 *        type: "string"
 *        default: ""
 *        description: 产品材质
 *      specifications:
 *        type: "string"
 *        default: ""
 *        description: 产品规格
 *      features:
 *        type: "string"
 *        default: ""
 *        description: 产品特性
 *      status:
 *        type: "string"
 *        default: "0"
 *        description: 状态 0=正常，1=停用
 *      showImg:
 *        type: "string"
 *        default: ""
 *        description: 产品详细图片展示,图片地址以逗号分隔的形式上传
 *      remark:
 *        type: "string"
 *        default: ""
 *        description: 备注
 *      classifyId:
 *        type: "string"
 *        default: "101"
 *        description: 产品分类
 */

/**
 * @swagger
 * /apis-admin/login:
 *   post:
 *     summary: 后台管理端-登录
 *     description:  根据账号密码查询管理员信息，返回一个token,登录管理系统
 *     tags:
 *       - 登录
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/loginParam'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 */

/**
 * @swagger
 * /apis-admin/register:
 *   post:
 *     summary: 后台管理端-注册
 *     description:  注册账号
 *     tags:
 *       - 登录
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/loginParam'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 */

/**
 * @swagger
 * /apis-admin/logout:
 *   post:
 *     summary: 后台管理端-退出登录
 *     description:  退出登录
 *     tags:
 *       - 登录
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 */

router.post('/login', login) // 登录
router.get('/logout', logout) // 退出
router.post('/register', register) // 注册
router.post('/forget_password', forgetPassword) // 修改密码
router.post('/update_info', token.verifyToken, updateInfo)

router.post('/system/user/profile/avatar', token.verifyToken, profileAvatar)

// 新增
/**
 * @swagger
 * /apis-admin/classify/add:
 *   post:
 *     summary: 新增产品分类
 *     description:  新增产品分类
 *     tags:
 *       - 后台管理-产品分类
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/addClassifyBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.post('/classify/add', token.verifyToken, classifyAdd)
// 删除
/**
 * @swagger
 * /apis-admin/classify/delete/{ids}:
 *   delete:
 *     summary: 根据产品ID删除数据库中产品数据
 *     description: 根据产品ID删除数据库中产品数据
 *     tags: [后台管理-产品分类]
 *     parameters:
 *       - name: ids
 *         description: 要删除的ID列表，以逗号分隔
 *         required: true
 *         in: path
 *         type: string
 *         format: "int64"
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */

router.delete('/classify/delete/:ids', token.verifyToken, classifyDelete)
// 修改
/**
 * @swagger
 * /apis-admin/classify/edit:
 *   put:
 *     summary: 修改产品分类
 *     description:  修改产品分类
 *     tags:
 *       - 后台管理-产品分类
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/editClassifyBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */

router.put('/classify/edit', token.verifyToken, classifyEdit)
// 产品分类列表
/**
 * @swagger
 * /apis-admin/classify/list:
 *   get:
 *     summary: 产品分类列表数据
 *     description: 根据分页信息查询产品分类数据，返回一个分类列表
 *     tags: [后台管理-产品分类]
 *     parameters:
 *       - name: pageNum
 *         description: 分页页数
 *         required: true
 *         in: query
 *         type: string
 *       - name: pageSize
 *         description: 分页条数
 *         in: query
 *         required: true
 *         type: string
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.get('/classify/list', token.verifyToken, classifyList)

// 增加
/**
 * @swagger
 * /apis-admin/library/add:
 *   post:
 *     summary: 新增产品
 *     description:  新增产品
 *     tags:
 *       - 后台管理-产品库
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/addLibraryBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.post('/library/add', token.verifyToken, libraryAdd)
// 删除
/**
 * @swagger
 * /apis-admin/library/delete/{ids}:
 *   delete:
 *     summary: 根据产品ID删除数据库中产品数据
 *     description: 根据产品ID删除数据库中产品数据
 *     tags: [后台管理-产品库]
 *     parameters:
 *       - name: ids
 *         description: 要删除的ID列表，以逗号分隔
 *         required: true
 *         in: path
 *         type: string
 *         format: "int64"
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.delete('/library/delete/:ids', token.verifyToken, libraryDelete)
// 修改
/**
 * @swagger
 * /apis-admin/library/edit:
 *   put:
 *     summary: 修改产品
 *     description:  修改产品
 *     tags:
 *       - 后台管理-产品库
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/editLibraryBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.put('/library/edit', token.verifyToken, libraryEdit)
// 查询
// 产品库列表
/**
 * @swagger
 * /apis-admin/library/list:
 *   get:
 *     summary: 产品库列表数据
 *     description: 根据分页信息查询产品数据，返回一个产品列表
 *     tags: [后台管理-产品库]
 *     parameters:
 *       - name: pageNum
 *         description: 分页页数
 *         required: true
 *         in: query
 *         type: string
 *       - name: pageSize
 *         description: 分页条数
 *         in: query
 *         required: true
 *         type: string
 *       - name: status
 *         description: 状态
 *         in: query
 *         required: false
 *         type: string
 *       - name: title
 *         description: 标题
 *         in: query
 *         required: false
 *         type: string
 *       - name: classifyId
 *         description: 分类ID
 *         in: query
 *         required: false
 *         type: string
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.get('/library/list', token.verifyToken, libraryList)

// 增加
/**
 * @swagger
 * /apis-admin/notice/add:
 *   post:
 *     summary: 新增通知公告
 *     description:  新增通知公告
 *     tags:
 *       - 后台管理-通知公告
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/addNoticeBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.post('/notice/add', token.verifyToken, noticeAdd)

// 删除
/**
 * @swagger
 * /apis-admin/notice/delete/{ids}:
 *   delete:
 *     summary: 根据通知公告ID删除数据库中通知公告数据
 *     description: 根据通知公告ID删除数据库中通知公告数据
 *     tags: [后台管理-通知公告]
 *     parameters:
 *       - name: ids
 *         description: 要删除的ID列表，以逗号分隔
 *         required: true
 *         in: path
 *         type: string
 *         format: "int64"
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.delete('/notice/delete/:ids', token.verifyToken, noticeDelete)
// 修改
/**
 * @swagger
 * /apis-admin/notice/edit:
 *   put:
 *     summary: 修改通知公告
 *     description:  修改通知公告
 *     tags:
 *       - 后台管理-通知公告
 *     consumes:
 *      - application/json
 *      - application/xml
 *     produces:
 *      - application/json
 *      - application/xml
 *     parameters:
 *       - name: body
 *         in: body
 *         schema:
 *          $ref: '#/definitions/editNoticeBody'
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.put('/notice/edit', token.verifyToken, noticeEdit)

// 查询 - 通知公告列表
/**
 * @swagger
 * /apis-admin/notice/list:
 *   get:
 *     summary: 通知公告列表数据
 *     description: 根据分页信息查询产品数据，返回一个产品列表
 *     tags: [后台管理-通知公告]
 *     parameters:
 *       - name: pageNum
 *         description: 分页页数
 *         required: true
 *         in: query
 *         type: string
 *       - name: pageSize
 *         description: 分页条数
 *         in: query
 *         required: true
 *         type: string
 *       - name: status
 *         description: 状态
 *         in: query
 *         required: false
 *         type: string
 *       - name: title
 *         description: 标题
 *         in: query
 *         required: false
 *         type: string
 *       - name: classifyId
 *         description: 分类ID
 *         in: query
 *         required: false
 *         type: string
 *     responses:
 *       '200':
 *         description: Ok
 *         schema:
 *           type: 'object'
 *           properties:
 *             code:
 *               type: 'number'
 *               description: 成功状态码
 *             data:
 *               type: 'object'
 *               description: 返回数据
 *             message:
 *               type: 'string'
 *               description: 消息提示
 *       '400':
 *         description: 操作失败
 *       '404':
 *         description: not found
 *     security:
 *       - Bearer: []
 */
router.get('/notice/list', token.verifyToken, noticeList)
module.exports = router